﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;

namespace AgvPublic
{
    public class SerialPro
    {
        SerialPort comPort;
        public SerialPro()
        {
            string[] ports = SerialPort.GetPortNames();
            comPort = new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One);
        }

        public void Open()
        {
            if(!comPort.IsOpen)
            comPort.Open();
        }

        public bool IsOpen()
        {
            return comPort.IsOpen;
        }

        public void SendData(byte[] buffer)
        {
            if (comPort.IsOpen)
            {
                comPort.Write(buffer, 0, buffer.Length);
            }
        }

        public void Dispose()
        {
            if (comPort.IsOpen)
            {
                comPort.Dispose();
            }
        }
    }
}
